const query = (responseChannel:string, sql: string, values: any[]) => new Promise((resolve, reject) => {
    window.ipcRenderer.send("dbQuery",responseChannel, sql, values)
    window.ipcRenderer.on(responseChannel, (event, data) => {
        resolve(data)
    })
})
export const getOrders = () => query("getOrdersResponse",
    "select o.*, c.CustomerCode,c.CustomerName from orders o left join customers c on c.CustomerID=o.CustomerID",
    [])
export const getCurrencies = () => query("getCurrenciesResponse","select * from currencies", [])
export const getCustomers = () => query("getCustomersResponse","select * from customers", [])
export const getPayterms = () => query("getPaytermsResponse","select * from payterms", [])
export const getOrderDetails = (orderId:number)=> query("getOrderDetailsResp", 
"select od.*, g.Number as GoodsNum, g.GoodsName, g.ID as GoodsID, "
+" box.Num as BoxNum, box.Name as BoxName, "
+" p.PapperCode "
+" from orderdetails od "
+"left join customerspecialtemnumbers g on g.ID=od.CustomerGoodsID "
+"left join boxinfos box on box.ID=od.BoxInfoID "
+"left join papperinfos p on p.ID=od.PapperInfoID "
+"where od.OrderId=?",
 [orderId]) 

 export const getCustomerGoods = (customerID:number)=>query("getCustomerGoodsResp", 
 "select g.*,g.ID as CustomerGoodsID from customerspecialtemnumbers g"
 + " left join boxinfos b on b.ID=g.BoxInfoID"
 + " left join papperinfos p on p.ID=g.PapperInfoID"
 + " where g.CustomerID=? ", [customerID])

